package pos.data;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import pos.domain.CentroCultural;




public class JDBCCentroCulturalDAO implements ICentroCulturalDAO {

	
	public List selectCentroCulturalBarrio(Connection conn, Integer barrioOID) {

		String sql = "SELECT* FROM CentroCultural C,Barrio B,BarrioCentroCultural BC WHERE B.barrioOID = BC.barrioOID AND C.centroCulturalOID = BC.centroCulturalOID AND B.barrioOID='"
				+ barrioOID + "'";

		PreparedStatement stmt = null;
		List searchResults = new LinkedList();
		ResultSet result = null;
		CentroCultural cen = null;

		try {
			stmt = conn.prepareStatement(sql);
			result = stmt.executeQuery();
			while (result.next()) {

				cen = new CentroCultural();
				cen.setCalle(result.getString("calle"));
				cen.setNombre(result.getString("nombre"));
				searchResults.add(cen);

			}

		} catch (SQLException e) {
			System.out.println("Message: " + e.getMessage());
			System.out.println("SQLState: " + e.getSQLState());
			System.out.println("ErrorCode: " + e.getErrorCode());
		} finally {
			try {
				if (result != null) {
					result.close();
				}
				if (stmt != null) {
					stmt.close();
				}
			} catch (SQLException e) {
			}
		}

		return searchResults;
	}

	
	
}
